//
//  LGHomeViewController.swift
//  LGWeibo
//
//  Created by 李更 on 8/9/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit

//设置重用标识
let LGHomeViewCellId = "LGHomeViewCellId"

class LGHomeViewController: LGVisitorViewController {
    
    
    
    private lazy var statusListViewMode : LGStatusListviewModel = LGStatusListviewModel()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        if !isLogin {
        visitorView?.setUpVisitor(nil, title: nil)
            return
        }
       
        setuptableViewInfo()
        statusListViewMode.loadData { (isSuccess) in
            if !isSuccess{
            print("请求失败")
                return
            }
            print("请求成功")
            self.tableView.reloadData()
        }
    }
    
    
    func setuptableViewInfo(){
        //注册cell
        tableView.registerClass(LGStatusCell.self, forCellReuseIdentifier: LGHomeViewCellId)
        
        //设置代理
        tableView.dataSource = self
        //自动设置行高
        tableView.rowHeight = UITableViewAutomaticDimension
        //预估行高
          tableView.estimatedRowHeight = 200
        
    }
   

}
extension LGHomeViewController : UITableViewDataSource{
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusListViewMode.dataArray.count
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(LGHomeViewCellId, forIndexPath: indexPath) as! LGStatusCell
        
        
        cell.statusViewModel = statusListViewMode.dataArray[indexPath.row]
    
        return cell
        
    }
    
}


